//
// calc.cpp for calc.cpp in /home/druart_p/Work/math/my-math-epi/202
// 
// Made by pierrick druart
// Login   <druart_p@epitech.net>
// 
// Started on  Sun Mar 11 14:10:00 2012 pierrick druart
// Last update Sun Mar 11 15:27:50 2012 pierrick druart
//

#include <math.h>

#include "Calc.hh"

// Constructor && Destructor

Calc::Calc() {}

Calc::~Calc() {}

// Function

double		Calc::conj(int x, int y) const
{
  double	res;
  double	X;
  double	Y;

  X = x;
  Y = y;
  res = (((6-X)*(7-Y)) / 300);
  return (res);
}

double		Calc::prob(int z) const
{
  int		x;
  int		y;
  double	res = 0.0;

  x = 1;
  while (x <= 5)
    {
      y = 1;
      while (y <= 5)
	{
	  if (x+y == z)
	    res += conj(x, y);
	  y++;
	}
      x++;
    }
  return (res);
}

double		Calc::rep(int z) const
{
  double	res = 0.0;
  int		i;

  i = 2;
  while (i <= z)
    {
      res += prob(i);
      i++;
    }
  return (res);
}

// Marginale

double		Calc::marg_x(int x) const
{
  double	res;

  res = conj(x, 1) + conj(x, 2) + conj(x, 3) + conj(x, 4) + conj(x, 5);
  return (res);
}

double		Calc::marg_y(int y) const
{
  double	res;

  res = conj(1, y) + conj(2, y) + conj(3, y) + conj(4, y) + conj(5, y);
  return (res);
}

// Esperance

double		Calc::E_x() const
{
  double	res;

  res = marg_x(1) + (2 * marg_x(2)) + (3 * marg_x(3)) + (4 * marg_x(4)) + (5 * marg_x(5));
  return (res);
}

double		Calc::E_y() const
{
  double	res;

  res = marg_y(1) + (2 *marg_y(2)) + (3 * marg_y(3)) + (4 * marg_y(4)) + (5 * marg_y(5));
  return (res);
}


double		Calc::E_z() const
{
  double	res;

  res = (((2 * prob(2)) + (3 * prob(3)) + (4 * prob(4)) + (5 * prob(5)) + (6 * prob(6)) + (7 * prob(7)) + (8 * prob(8)) + (9 * prob(9)) + (10 * prob(10))));
  return (res);
}

// Variance

double		Calc::Var_x() const
{
  double	res;
  double	E_t;

  E_t = E_x();
  res = (double)((pow((1 - E_t), 2) * marg_x(1)) + (pow((2 - E_t), 2) * marg_x(2)) + (pow((3 - E_t), 2) * marg_x(3)) + (pow((4 - E_t), 2) * marg_x(4)) + (pow((5 - E_t), 2) * marg_x(5)));
  return (res);
}

double		Calc::Var_y() const
{
  double	res;
  double	E_t;

  E_t = E_y();
  res = (double)((pow((1 - E_t), 2) * marg_y(1)) + (pow((2 - E_t), 2) * marg_y(2)) + (pow((3 - E_t), 2) * marg_y(3)) + (pow((4 - E_t), 2) * marg_y(4)) + (pow((5 - E_t), 2) * marg_y(5)));
  return (res);
}

double		Calc::Var_z() const
{
  double	res;
  double	E_t;

  E_t = E_z();
  res = (double)((pow((2 - E_t), 2) * prob(2)) + (pow((3 - E_t), 2) * prob(3)) + (pow((4 - E_t), 2) * prob(4)) + (pow((5 - E_t), 2) * prob(5)) + (pow((6 - E_t), 2) * prob(6)) + (pow((7 - E_t), 2) * prob(7)) + (pow((8 - E_t), 2) * prob(8)) + (pow((9 - E_t), 2) * prob(9)) + (pow((10 - E_t), 2) * prob(10)));
  return (res);
}
